<template>
	<view>
		<view class="od-banner">
			<image class="od-banner-icon" src="../../static/images/od_bg_icon.png" mode="widthFix" />
			<view :class="'od-jd od-jd-' + orderStatus">
				<view class="od-jd-out">
					<view class="od-jd-in"></view>
				</view>
				<view class="vp-flex od-jd-text">
					<view class="vp-flex_1">
						<text class="od-jd-st-0">填写订单</text>
					</view>
					<view class="vp-flex_1">
						<text class="od-jd-st-10">等待陪诊</text>
					</view>
					<view class="vp-flex_1">
						<text class="od-jd-st-20">等待接单</text>
					</view>
					<view class="vp-flex_1">
						<text class="od-jd-st-30">服务进行</text>
					</view>
					<view class="vp-flex_1">
						<text class="od-jd-st-40">服务完成</text>
					</view>
				</view>
			</view>
		</view>

		<view class="od-box">
			<view class="weui-cells">
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label od-box-tt">预约信息</view>
					</view>
					<view class="weui-cell__bd"></view>
				</view>

				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">陪诊员</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{ order.escortInfo.name }}
						</view>
					</view>
				</view>

				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">电话</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{ order.escortInfo.escortPhone }}
						</view>
					</view>
				</view>

				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">预约服务</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{ order.type }}
						</view>
					</view>
				</view>
				<block v-if="order.stype == 1">
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">就诊医院</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.hospitalName }}
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">预约陪诊时间</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								<text>{{order.orderStartTime}}</text>
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">就诊人</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>{{ order.patientInfo.patientName }} {{ order.patientInfo.sex == 1 ? '男' : '女' }}
								{{ order.patientInfo.age }}岁
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">就诊人电话</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.patientInfo.patientPhone }}
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">下单人</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
							  {{ order.nickname !== undefined && order.nickname !== null ? order.nickname : '微信用户' }}
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">下单人电话</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.tel }}
							</view>
						</view>
					</view>
					<block v-if="order.stype == 3">
						<view class="weui-cell">
							<view class="weui-cell__hd">
								<view class="weui-label">接送地址</view>
							</view>
							<view class="weui-cell__bd"></view>
							<view class="weui-cell__ft">
								<view>
									{{ order.receiveAddress }}
								</view>
							</view>
						</view>
					</block>
				</block>

				<!-- 代跑取药 -->
				<block v-if="order.service_stype == 3">
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">所在医院</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.hospitalName }}({{order.hospitalAddress}})
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">期望处理时间</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{order.orderStartTime}}
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">收件人</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>{{ order.patientInfo.patientName }} {{ order.patientInfo.patientphone }}</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">收件地址</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.patientInfo.patientAddress }}
							</view>
						</view>
					</view>
				</block>
				<!-- <block v-if="order.service_stype > 100">
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">期望服务时间</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								<formater :timestamp="order.starttime" format="YYYY-MM-dd hh:mm"></formater>
							</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">服务对象</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>{{ order.client_name }} {{ order.client_sex == 1 ? '男' : '女' }}
								{{ order.client_age }}周岁</view>
						</view>
					</view>
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">服务对象电话</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.client_mobile }}
							</view>
						</view>
					</view>

					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">服务地址</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								{{ order.address.address }}
							</view>
						</view>
					</view>
				</block> -->
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">其他需求</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{ order.demand }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="od-box">
			<view class="weui-cells">
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label od-box-tt">订单信息</view>
					</view>
					<view class="weui-cell__bd"></view>
				</view>
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">联系电话</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{ order.tel }}
						</view>
					</view>
				</view>

				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">下单时间</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							<text>{{order.createTime}}</text>
						</view>
					</view>
				</view>
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">应付金额</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>{{ order.orderPrice }}元</view>
					</view>
				</view>
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">实付金额</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>{{ order.orderPrice }}元</view>
					</view>
				</view>
				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">付款时间</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view>
							{{order.createTime}}
						</view>
					</view>
				</view>

				<view class="weui-cell">
					<view class="weui-cell__hd">
						<view class="weui-label">订单编号</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft">
						<view class="color_click">
							{{ order.orderCode }}
						</view>
					</view>
				</view>

				<navigator class="weui-cell weui-cell_access" url="../index/server">
					<view class="weui-cell__hd">
						<view class="weui-label">联系客服</view>
					</view>
					<view class="weui-cell__bd"></view>
					<view class="weui-cell__ft weui-cell__ft_in-access">疑问或投诉</view>
				</navigator>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		computed,
		ref
	} from 'vue';
	import mynavbar from '@/components/navbar/navbar.vue'
	import UQRCode from 'uqrcodejs';
	const navigateto = () => {
		uni.navigateTo({
			url: '/pages/mysearch/index'
		})
	}
	const app = getApp()
	onLoad((options) => {
		getOrderDetail(options.orderCode)
	})
	let order = ref({})
	const orderStatus = computed(() => {
		console.log('Current order status:', order.value.orderStatus); // 调试输出
		let mymap = {
			3: '10', //待陪诊
			1: '20', //待接单
			4: '30', //陪诊中
			5: '40', //已完成
			6: '50' //已取消
		}
		console.log(mymap[order.value.orderStatus])
		return mymap[order.value.orderStatus]
	})
	const getOrderDetail = (orderCode) => {
		app.globalData.utils.myrequest({
			myurl: '/order/detail',
			header: {
				'Authorization': uni.getStorageSync('token'),
				'Source-Platform': 'mini-program'
			},
			data: {
				orderCode: orderCode
			},
			mysuccess: (res) => {
				console.log('订单详情res', res);
				order.value = res.data
			},
			myfail: (err) => {
				console.log('获取订单详情信息错误', err);
				return uni.showToast({
					title: '获取订单详情信息错误',
					icon: 'error'
				})
			}

		})

	}
	const onCounterOver = () => {
		getOrderDetail()
	}

	const dopay = () => {

		console.log("订单信息", order);
		app.globalData.utils.myrequest({
			myurl: '/order/pay',
			method: 'GET',
			data: {
				orderCode: order.orderCode
			},
			header: {
				'Authorization': uni.getStorageSync('token'),
				'Source-Platform': 'mini-program'
			},
			mysuccess: (res) => {
				console.log('订单支付信息', res);
				uni.showToast({
					title: '支付成功',
					duration: 2000,
					icon: 'success'
				});
				uni.switchTab({
					url: '../myorder/index'
				});
			},
			myfail: (err) => {
				console.log('订单支付错误信息', err);
				return uni.showToast({
					title: '支付失败',
					icon: 'error'
				});
			}
		})

	}

	const makePhoneCall = (e) => {
		uni.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.tel
		})
	}
</script>

<style>
	@import url('order.css');
</style>